<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>预付款页面</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var allFundState = ${allFundState};
    var allFundPayType = ${allFundPayType};
    var formSetting = {
        title: "预付款业务数据",
        module: 'save',
        numCount: '3',
        columns: [{
            index: "ID",
            name: "id",
            hidden: true,
            label: "id"
        }, {
            index: "BID",
            name: "bid",
            readonly: true,
            type: "dropdown",
            label: "预付款编号"
        }, {
            index: "STATE",
            name: "state",
            readonly: true,
            type: "dropdown",
            label: "当前状态"
        }, {
            index: "FUND_PAY_TYPE",
            name: "fundPayType",
            type: "dropdown",
            data: allFundPayType,
            label: "付款方式"
        }, {
            index: "AMOUNT",
            name: "amount",
            label: "预付款金额(元)"
        }, {
            index: "TRANSFERCERTIFICATE_ID",
            name: "transferCertificate.id",
            readonly: true,
            label: "TRANSFERCERTIFICATE_ID",
            hidden: true
        }, {
            index: "SHUIDAN_NO",
            name: "shuiDan",
            label: "水单号"
        }],
        form: {
            'url': 'ajustment-saveOrUpdate',
            'data': function () {
                var id = "${id}";
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "ajustment-find?id=" + id,
                               async: false,
                               cache: false,
                               success: function (data) {
                                   dataValue = data;
                               }
                           });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                location.href = 'ajustment-main';
            }
        },
        buttons: {
            custom: [{
                id: "orderBtn",
                value: "提交数据",
                click: function () {
                    $("input[name='state']").val("INIT");
                    var fundPayType = $("input[name='fundPayType']").val();
                    var shuidanVal = $("input[name='shuiDan']").val();
                    if (fundPayType == "") {
                        alert("请先选择付款方式!");
                        return;
                    }
                    if ($("input[name='amount']").val() == "") {
                        alert("请先填写预付款金额!");
                        return;
                    }
                    if ("TRANSFER" == fundPayType && shuidanVal == "") {
                        alert("请填写水单号!");
                        return;
                    }
                    if ("TRANSFER" == fundPayType) {
                        var fileUploadTr = $($("iframe")[0].contentDocument.body).find(
                            "tr.jqgrow.ui-row-ltr");
                        var tFileLen = fileUploadTr.length;
                        if (tFileLen == 0) {
                            alert("线下转账必需上传水单!");
                            return;
                        } else if (tFileLen > 1) {
                            alert("多份水单请打包上传！");
                            return;
                        }
                        $("input[name='transferCertificate.id']").val(fileUploadTr.attr('id'));
                    }
                    if ("TRANSFER" == fundPayType && shuidanVal != "") {
                        var shuidan = shuidanVal;
                        $.ajax({
                                   url: "ajustment-checkShuiDan?shuidan=" + shuidan,
                                   async: false,
                                   cache: false,
                                   success: function (data) {
                                       if (!data) {
                                           return;
                                       }
                                       var msg = data.msg ? $.parseJSON(data.msg) : "";
                                       if (msg !== undefined && msg != "") {
                                           var state = msg.state;
                                           var msg = msg.msg;
                                           if (state == "0") {
                                               jw.alert(msg);
                                               return;
                                           } else if (state == "1") {
                                               //提交
                                               $("#saveButton").click();
                                           }
                                       }
                                   }
                               });
                    } else {
                        $("#saveButton").click();
                    }
                }
            }]
        }
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
        var fundPayType = $("input[name='fundPayType']");
        if ("ONLINE" == fundPayType.val() || "WechatPay" == fundPayType.val() || "Alipay" == fundPayType.val()) {
            location.href = "ajustment-onlinePay?id=" + "${id}";
            return;
        }

        var state = $("input[name='state']");
        var stateDropdown = $("input[name='control_fundAjustment_state_dropdown']");
        state.val(state.val() == "" ? "TEMP" : state.val());
        stateDropdown.val(stateUtil.get(allFundState, state.val()));
        $("input[name='control_fundAjustment_bid_dropdown']").val(
            $("input[name='bid']").val());

        $("#saveButton").val("保存草稿");
        $("#orderBtn").css("color", "green");
//        if (state.val() == "INIT") {
        $("#saveButton").hide();
//        }

        var transferCertificate = $("input[name='transferCertificate.id']");
        var id__ = '${id}';
        if (id__ === '') {
            id__ = "PAYMENT_TRANSFER_" + Math.round(Math.random() * 10000);
        }

        $("#attachmentFrame").attr("src", "../business/uploadMain?type=payMent#" + id__);
        if (state.val() == "SUCCESS") {
            $("#saveButton").hide();
            $("#orderBtn").hide();
            $("input[name='amount']").attr("disabled", true);
            $("input[name='control_fundAjustment_fundPayType_dropdown']").attr("disabled", true);
            $("#attachmentFrame")[0].onload = function () {
                $("#attachmentFrame").contents().find("#mf_container0").hide()
            };
        }
    });
    var stateUtil = {
        get: function (arras, key) {
            for (var a in arras) {
                if (arras[a][1] == key) {
                    return arras[a][0];
                }
            }
        }
    }
    function uploadSuccessBizCallBack(id) {
        $("input[name='transferCertificate.id']").val(id)
        //fix P01261
        $("#orderBtn").click();
    }
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
<fieldset class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
    <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header">
        <a
                href="javascript:void(0)"
                class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
                class="ui-icon ui-icon-circle-triangle-s"></span> </a><span
            class="replace-ui-jqgrid-title">水单附件</span>
    </div>
    <iframe id="attachmentFrame" style="width:100%;" scrolling="no" frameborder="0"
            onload="this.height=(this.contentWindow.document.documentElement.scrollHeight+30)"></iframe>
</fieldset>
<fieldset class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
    <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header">
        <a
                href="javascript:void(0)"
                class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
                class="ui-icon ui-icon-circle-triangle-s"></span> </a><span
            class="replace-ui-jqgrid-title">预付款说明</span>
    </div>
    <p> 请填写预付款金额、付款方式。 </p>
    <p> 付款方式：支票、现金、转账。 </p>
    <p> 如果是付款方式为转账的话，必须上传水单。 </p>
    <p> 预付款记录通过审核后，金额会转入账户余额。审核时间为转账后1-2个工作日。 </p>
    <p><font color="red"> 开户名称：佛山市佛航展翔物流有限公司 </font></p>
    <p><font color="red"> 开户行：中国农业银行佛山惠景支行 </font></p>
    <p><font color="red"> 账号：44422901040007626 </font></p>
    <p><br/></p>
</fieldset>
</body>
</html>
